package com.yjjxt

import org.apache.spark.{SparkConf, SparkContext}

object Hello21CountByKeyValue {
  def main(args: Array[String]): Unit = {
    val sparkContext = new SparkContext((new SparkConf().setMaster("local").setAppName("Join" + System.currentTimeMillis())))
    val array1 = Array[String]("Hello1 user1", "Hello1 user1", "Hello user11", "Hello user12", "user1 apple1")

    val lines1 = sparkContext.parallelize(array1, 3)
    lines1.countByValue().foreach(ele => {
      println(ele._1 + "--" + ele._2)
    })

    val words1 = lines1.map(ele => (ele.split(" ")(0), ele.split(" ")(1)))
    words1.countByKey().foreach(ele => {
      println(ele._1 + "==" + ele._2)
    })


    sparkContext.stop()
  }
}
